<?php use_helper('jQuery')?>
<?php use_stylesheets_for_form($form) ?>
<?php use_javascripts_for_form($form) ?>

<?php echo jq_javascript_tag()?>
    <?php if($form->getObject()->getType()->getUsesMessage() &&
            ($form->getObject()->getType()->getType() == 'Email')): ?>
        <?php echo '
            function setMsg(){
                msg = tinyMCE.get("ems_section_Home_html").getContent();
                $("textarea#ems_service_button_message").val(msg);
            }
            function startCallback() {
                setMsg();
                clearView();
                showLoaderMain();
                return true;
            }'
        ?>
    <?php else : ?>
        <?php echo '
            function startCallback(){
                clearView();
                showLoaderMain();
                return true;
            }'
        ?>
    <?php endif; ?>

    function completeCallback(response) {
        document.getElementById("main").innerHTML = response;
        <?php echo jq_remote_function(array(
                'update'   => 'ajax_holder_for_multi_update',
                'url'      => url_for('servicebutton_multiupdate', $form->getObject()),
                'complete' => 'hideLoader();createTree();activateTreeMenu();',
                'script'   => true
            ))?>
    }

    <?php echo 'initServiceButtonFileUpload("'.
         url_for('servicebutton_tempfileupload',$form->getObject()).
                '?portal_id='.$form->getObject()->getPortalId().'");'
    ?>
<?php echo jq_end_javascript_tag() ?>

<div id="main_header" class="ui-widget-header ui-corner-all">
    <h3>Editando el Boton de Servicio: "<?php echo $form->getObject()->getType() ?>"</h3>
</div>
<div id="main_content" class="ui-widget ui-widget-content ui-corner-all">
    <div class="form">
        <?php echo jq_form_remote_tag(
                array(
                    'update' => 'main',
                    'url' => ($form->getObject()->isNew() ?
                                url_for('servicebutton_create',$form->getObject()->getPortal())
                                :
                                url_for('servicebutton_update', $form->getObject())
                                ),
                    'before'   => ($form->getObject()->getType()->getType() == 'Email' ?
                                    'setServiceButtonMessage();' : '').'hideMainContent();showLoaderMain();',
                    'complete' => 'hideLoader();showMainContent();',
                    'script'   => true
                ),array(
                    'id' => 'file_upload',
                    'class' => 'form_menu'
                ))?>
            <?php if (!$form->getObject()->isNew()): ?>
                <input type="hidden" name="sf_method" value="put" />
            <?php endif; ?>
            <?php echo $form->renderHiddenFields() ?>
            <?php echo $form->renderGlobalErrors() ?>
            <fieldset>
                <div class="form-row first-row">
                    <?php echo $form['thumb_small_tmp']->renderError() ?>
                    <table id="files_thumb_small" class="upload-files-table drop-zone">
                        <?php if ($form['thumb_small']->getValue()): ?>
                            <tr>
                                <td>Archivo actual:</td>
                                <td class="file-preview">
                                    <img alt="<?php echo $form['thumb_small']->getValue()?>"
                                         src="<?php echo '/uploads/portal_'.
                                            $form->getObject()->getPortalId().
                                            ($form->getObject()->getThumbSmall() ?
                                                    (!$form->isBound() ?
                                                        '/images/'
                                                        :
                                                        ($form['thumb_small']->getValue() == $form->getObject()->getThumbSmall() ?
                                                            '/images/'
                                                            :
                                                            '/temp_files/'
                                                        )
                                                    )
                                                        :
                                                    '/temp_files/').
                                            basename($form['thumb_small']->getValue())
                                        ?>">
                                </td>
                                <td class="file-size">
                                    Tamaño del archivo: <?php echo round(($form['thumb_small_size']->getValue()/1024),2) ?> Kb
                                </td>
                            </tr>
                        <?php endif;?>
                    </table>
                    <?php echo $form['thumb_small_tmp']->renderLabel() ?>
                    <div id="drop_zone_thumb_small" class="form-field">
                        <?php echo $form['thumb_small_tmp']->render() ?>
                        <div>Archivo a cargar</div>
                    </div>
                    <?php echo $form['thumb_small_tmp']->renderHelp() ?>
                </div>
                <div class="form-row">
                    <?php echo $form['thumb_big_tmp']->renderError() ?>
                    <table id="files_thumb_big" class="upload-files-table">
                        <?php if ($form['thumb_big']->getValue()): ?>
                            <tr>
                                <td>Archivo actual:</td>
                                <td class="file-preview">
                                    <img alt="<?php echo $form['thumb_big']->getValue()?>"
                                         src="<?php echo '/uploads/portal_'.
                                            $form->getObject()->getPortalId().
                                            ($form->getObject()->getThumbBig() ?
                                                    (!$form->isBound() ?
                                                        '/images/'
                                                        :
                                                        ($form['thumb_big']->getValue() == $form->getObject()->getThumbBig() ?
                                                            '/images/'
                                                            :
                                                            '/temp_files/'
                                                        )
                                                    )
                                                        :
                                                    '/temp_files/').
                                            basename($form['thumb_big']->getValue())
                                        ?>">
                                </td>
                                <td class="file-size">
                                    Tamaño del archivo: <?php echo round(($form['thumb_big_size']->getValue()/1024),2) ?> Kb
                                </td>
                            </tr>
                        <?php endif;?>
                    </table>
                    <?php echo $form['thumb_big_tmp']->renderLabel() ?>
                    <div id="drop_zone_thumb_big" class="form-field drop-zone">
                        <?php echo $form['thumb_big_tmp']->render() ?>
                        <div>Archivo a cargar</div>
                    </div>
                    <?php echo $form['thumb_big_tmp']->renderHelp() ?>
                </div>
                <?php if(isset ($form['message'])): ?>
                    <div class="form-row">
                        <?php echo $form['message']->renderLabel() ?>
                        <div class="form-field">
                            <?php echo $form['message']->renderError() ?>
                            <?php echo $form['message']->render() ?>
                        </div>
                    </div>
                <?php endif; ?>
                <div class="form-row">
                    <?php echo $form['published']->renderLabel() ?>
                    <div class="form-field">
                        <?php echo $form['published']->renderError() ?>
                        <?php echo $form['published']->render() ?>
                    </div>
                </div>
            </fieldset>
            <div id="form_buttons" class="ui-widget">
                <input class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only ui-button-text"
                       type="submit" value="Guardar" title="Guardar"/>
                <?php if($form->getObject()->isNew()):?>
                    <?php echo jq_link_to_remote(
                        '<span class="ui-button-text">Cancelar</span>',
                        array(
                            'update' => 'main',
                            'url' => url_for('portal_show', $form->getObject()->getPortal()),
                            'before' => 'clearView();showLoaderMain();',
                            'complete' => 'hideLoader()',
                            'script' => true
                        ),
                        array(
                            'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only',
                            'title' => 'Cancelar'
                        ))
                    ?>
                <?php else: ?>
                    <?php echo jq_link_to_remote(
                            '<span class="ui-button-text">Cancelar</span>',
                        array(
                            'update' => 'main',
                            'url' => url_for('servicebutton_show',$form->getObject()),
                            'before' => 'clearView();showLoaderMain();',
                            'complete' => 'hideLoader()',
                            'script' => true
                        ),
                        array(
                            'class' => 'ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only',
                            'title' => 'Cancelar'))
                    ?>
                <?php endif; ?>
            </div>
        </form>
    </div>
</div>